<template>
  <el-dialog v-model="dialogVisible" title="编辑" width="400px">
    <el-form label-width="50px" :model="data">
      <el-form-item label="姓名">
        <el-input v-model="data.name" placeholder="请输入姓名" />
      </el-form-item>
      <el-form-item label="籍贯">
        <el-input v-model="data.place" placeholder="请输入籍贯" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="add">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
// TODO: 编辑
import {defineExpose, inject, ref } from 'vue'
import axios from 'axios'
// const data = ref({})
// 弹框开关
const dialogVisible = ref(false)
//*拿到数据 并回显表单
  const data = inject('data')
//* 打开弹框
const validata = () =>{
  dialogVisible.value = true
}
//* 父组件调用 方法 打开弹窗
defineExpose({
  validata
})
//*确认
const add = ()=>{
  const id = data.value.id
  axios.patch(`/edit/${id}`, {
  name: data.value.name,
  place: data.value.place,
})
  // delList()  //* 重新渲染列表  不知道 怎么获取父组件的 方法
dialogVisible.value = false  // 关闭弹窗
}
</script>

<style scoped>
.el-input {
  width: 290px;
}
</style>
